/*Author: Seungbeom Ma
 *SJSU 
 * DATE: NOV 16
 * */

package com.example.projectmobilecloud;

import android.os.Bundle;
import android.app.Activity;

import android.content.Intent;

import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import tool.screen.selection.MainSelection_Tool;


public class MainActivity extends Activity {
	
	  // Main tool and interface references
	  public MainSelection_Tool mt = new MainSelection_Tool();
	  private RadioGroup radioSexGroup;
	  private RadioGroup radioWorkGroup;
	  private RadioGroup radioEnergyWorkGroup;
	  private CheckBox enable_energy;
	  private CheckBox enable_Custom;
	  private CheckBox enable_Custom_mb;
	  private EditText mEdit;
	  private Button btnDisplay;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		addListenerOnButton();
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	//Option: 
	//WORKFLOW_NUMBERS: 1 -> 20 tasks
	//				 	2 -> 50 tasks
	//					3 -> 100 tasks
	//RUNNING_MODE    : 1 -> Local Only
	//				    2 -> Cloud Only
	//					3 -> Local && Cloud
	
	public void addListenerOnButton() {
		 // Radio interface
		radioSexGroup = (RadioGroup) findViewById(R.id.radioSex);
		radioWorkGroup = (RadioGroup) findViewById(R.id.radioWorkFlow);
		radioEnergyWorkGroup = (RadioGroup)findViewById(R.id.radioEnergyWorkFlow);
		// check box interface
		enable_energy = (CheckBox)findViewById(R.id.ck_en_able);
		enable_Custom =(CheckBox)findViewById(R.id.ck_CM_Test);
		enable_Custom_mb =((CheckBox)findViewById(R.id.ck_CM_Test_MB));
		// Text box interface
		mEdit   = (EditText)findViewById(R.id.edittext);
		// Button interface
		btnDisplay = (Button) findViewById(R.id.btnDisplay);
		btnDisplay.setOnClickListener(new OnClickListener() {
	 
			public void onClick(View v) {
	 
			    // get selected radio button from radioGroup
				// get selection
				int selectedId = radioSexGroup.getCheckedRadioButtonId();
				int workflow_id = radioWorkGroup.getCheckedRadioButtonId();
				int Energy_id = radioEnergyWorkGroup.getCheckedRadioButtonId();
				int Customized_Task_Num;
				if (mEdit.getText().toString().equals(""))
				{
					 Customized_Task_Num = -999;
				}
				else{
					 Customized_Task_Num = Integer.parseInt(mEdit.getText().toString());
				}
			
				
				boolean is_Checked = enable_energy.isChecked();
				boolean is_CM_Checked = enable_Custom.isChecked();
				boolean is_CM_MB_Checked = enable_Custom_mb.isChecked();
				Intent GO_Control = new Intent(MainActivity.this,ControlActivity.class);
				System.out.println("Energy_id---->"  + (Energy_id-2131165194));
				System.out.println("is_Checked---->"  + is_Checked);
				
				System.out.println( GO_Control);
				int WORKFLOW_NUMBERS =	mt.Get_Option(workflow_id, 0);
				int RUNNING_MODE =	mt.Get_Option(selectedId, 1);
				
				GO_Control.putExtra("WORKFLOW_NUMBERS", WORKFLOW_NUMBERS);
				GO_Control.putExtra("RUNNING_MODE", RUNNING_MODE);
				GO_Control.putExtra("Energy_id",Energy_id);
				GO_Control.putExtra("Is_Energy_checked",is_Checked);
				GO_Control.putExtra("Is_Energy_custom",is_CM_Checked);
				GO_Control.putExtra("CM_VALUE",Customized_Task_Num);
				GO_Control.putExtra("is_CM_MB_Checked",is_CM_MB_Checked);
			    System.out.println("LETS START");
			    startActivity(GO_Control);	 
			} 
		});
	  }
}
